<script setup>
import { ref, onMounted, getCurrentInstance } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { listFPService } from "@/api/FindPartner.js";

// 响应数据模型
const FPs = ref([]);
const pageNum = ref(1); // 当前页
const total = ref(20); // 总条数
const pageSize = ref(5); // 每页条数

//----------------获取找搭子列表数据------------------
const getFP = async () => {
  let params = {
    pageNum: pageNum.value,
    pageSize: pageSize.value,
    categoryId: 4,
    approvalStatus: 2,
  };

  try {
    let result = await listFPService(params);
    total.value = result.data.total;
    FPs.value = result.data.items;
  } catch (error) {
    ElMessage.error("获取搭子信息失败，请稍后重试");
  }
  console.log(FPs);
};
onMounted(() => {
  getFP();
});

// 分页条数据模型
const onSizeChange = (size) => {
  pageSize.value = size;
  pageNum.value = 1; // Reset to the first page when changing page size
  getFP();
}; // 修改每页条数
const onCurrentChange = (num) => {
  pageNum.value = num;
  getFP();
}; // 修改当前页

//----------------------显示帖子详情-------------------------
const showProductDetail = (product) => {
  const { title, content, image } = product;
  const message = `
    <h2>标题：${title}</h2>
    <p>搭子描述：${content}</p>
    <img src="${image}" alt="图片">
  `;
  ElMessageBox.confirm(message);
};
</script>

<!-- ================================================================================================== -->
<!-- **************************************************************************************************** -->
<!-- ================================================================================================== -->

<template>
  <!-- 找搭子信息页 -->
  <el-card>
    <el-carousel
      height="450px"
      direction="vertical"
      type="card"
      :autoplay="false"
    >
      <el-carousel-item v-for="item in FPs" :key="item.id">
        <el-card shadow="hover" :body-style="{ padding: '0px' }">
          <h3 text="2xl" justify="center">{{ item.title }}</h3>
          <el-button type="primary" @click="showProductDetail(item)"
            >查看详情</el-button
          >
        </el-card>
      </el-carousel-item>
    </el-carousel>
  </el-card>
</template>

<!-- ================================================================================================== -->
<!-- **************************************************************************************************** -->
<!-- ================================================================================================== -->

<style scoped>
.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

.el-carousel__item h3 {
  font-size: 14px; /* 调整标题字体大小 */
  margin-bottom: 12px; /* 调整标题下方边距 */
  text-align: left; /* 标题左对齐，根据需要调整 */
}

.el-carousel__item .el-button {
  margin-top: 12px; /* 调整按钮上方边距 */
}
</style>
